<template>

  <ProTable
    row-key="id"
    default-expand-all
    :filters="filters"
    :filter-form="filterForm"
    :columns="columns"
    :get-table-data="getData"
    custom-id="pro-table-test"
  > 
    <!-- 搜索条件 插槽 -->
    <template #filter_phone="{form, prop, bind}">
      <el-input-number v-model="form[prop]" :min="1" :max="10" />
    </template>
    
    <template #slotHeader_phone>
      插槽 手机号
    </template>
    <template #slot_phone="{ row }">
        插槽 {{ row.phone }}
    </template>
  </ProTable>
  <div style="color: black;">{{filterForm}}</div>

</template>

<script setup lang="ts">
import { h, ref } from 'vue'
import { ProTable, Table, FilterItem, TableColumnItem, PageResponse } from "@/components"


const filterForm = ref({aa:'1'})

const options = [
  {
    value: 'guide',
    label: 'Guide',
    children: [
      {
        value: 'disciplines',
        label: 'Disciplines',
        children: [
          {
            value: 'consistency',
            label: 'Consistency',
          },
          {
            value: 'feedback',
            label: 'Feedback',
          },
          {
            value: 'efficiency',
            label: 'Efficiency',
          },
          {
            value: 'controllability',
            label: 'Controllability',
          },
        ],
      },
      {
        value: 'navigation',
        label: 'Navigation',
        children: [
          {
            value: 'side nav',
            label: 'Side Navigation',
          },
          {
            value: 'top nav',
            label: 'Top Navigation',
          },
        ],
      },
    ],
  },
  {
    value: 'component',
    label: 'Component',
    children: [
      {
        value: 'basic',
        label: 'Basic',
        children: [
          {
            value: 'layout',
            label: 'Layout',
          },
          {
            value: 'color',
            label: 'Color',
          },
          {
            value: 'typography',
            label: 'Typography',
          },
          {
            value: 'icon',
            label: 'Icon',
          },
          {
            value: 'button',
            label: 'Button',
          },
        ],
      },
      {
        value: 'form',
        label: 'Form',
        children: [
          {
            value: 'radio',
            label: 'Radio',
          },
          {
            value: 'checkbox',
            label: 'Checkbox',
          },
          {
            value: 'input',
            label: 'Input',
          },
          {
            value: 'input-number',
            label: 'InputNumber',
          },
          {
            value: 'select',
            label: 'Select',
          },
          {
            value: 'cascader',
            label: 'Cascader',
          },
          {
            value: 'switch',
            label: 'Switch',
          },
          {
            value: 'slider',
            label: 'Slider',
          },
          {
            value: 'time-picker',
            label: 'TimePicker',
          },
          {
            value: 'date-picker',
            label: 'DatePicker',
          },
          {
            value: 'datetime-picker',
            label: 'DateTimePicker',
          },
          {
            value: 'upload',
            label: 'Upload',
          },
          {
            value: 'rate',
            label: 'Rate',
          },
          {
            value: 'form',
            label: 'Form',
          },
        ],
      },
      {
        value: 'data',
        label: 'Data',
        children: [
          {
            value: 'table',
            label: 'Table',
          },
          {
            value: 'tag',
            label: 'Tag',
          },
          {
            value: 'progress',
            label: 'Progress',
          },
          {
            value: 'tree',
            label: 'Tree',
          },
          {
            value: 'pagination',
            label: 'Pagination',
          },
          {
            value: 'badge',
            label: 'Badge',
          },
        ],
      },
      {
        value: 'notice',
        label: 'Notice',
        children: [
          {
            value: 'alert',
            label: 'Alert',
          },
          {
            value: 'loading',
            label: 'Loading',
          },
          {
            value: 'message',
            label: 'Message',
          },
          {
            value: 'message-box',
            label: 'MessageBox',
          },
          {
            value: 'notification',
            label: 'Notification',
          },
        ],
      },
      {
        value: 'navigation',
        label: 'Navigation',
        children: [
          {
            value: 'menu',
            label: 'Menu',
          },
          {
            value: 'tabs',
            label: 'Tabs',
          },
          {
            value: 'breadcrumb',
            label: 'Breadcrumb',
          },
          {
            value: 'dropdown',
            label: 'Dropdown',
          },
          {
            value: 'steps',
            label: 'Steps',
          },
        ],
      },
      {
        value: 'others',
        label: 'Others',
        children: [
          {
            value: 'dialog',
            label: 'Dialog',
          },
          {
            value: 'tooltip',
            label: 'Tooltip',
          },
          {
            value: 'popover',
            label: 'Popover',
          },
          {
            value: 'card',
            label: 'Card',
          },
          {
            value: 'carousel',
            label: 'Carousel',
          },
          {
            value: 'collapse',
            label: 'Collapse',
          },
        ],
      },
    ],
  },
  {
    value: 'resource',
    label: 'Resource',
    children: [
      {
        value: 'axure',
        label: 'Axure Components',
      },
      {
        value: 'sketch',
        label: 'Sketch Templates',
      },
      {
        value: 'docs',
        label: 'Design Documentation',
      },
    ],
  },
]

// 搜索条件
const filters: FilterItem[] = [
  {
    label: '名字',
    prop: 'name',
    value: 'xxx',
  },
  {
    type: 'input-number',
    label: '年龄',
    prop: 'age',
    value: 20,
  },
  {
    label: '手机号',
    prop: 'phone',
    value: '13600000000',
    slot: 'filter_phone'
  },
  {
    type: 'select',
    label: '状态',
    prop: 'status',
    multiple:true,
    list: [
      { value: 1, label: '普通' },
      { value: 2, label: '会员' },
      { value: false, label: '禁用' },
      { value: true, label: '启用' },
    ],
  },
  {
    type: 'cascader',
    label: '级联',
    prop: 'cascaderData',
    list: options
  },
  {
    type: 'datetime',
    label: '日期',
    prop: 'dateTime',
    value: '2024-01-01'
  },
  {
    type: 'datetimerange',
    label: '日期范围',
    prop: ['timeStart', 'timeEnd'],
    defaultShortcut: 'currentYear'
  }
]

// 列表字段
const columns: TableColumnItem[] = [
  {
    type: 'selection'
  },
  {
    type: 'drag',
    width: '80px',
    align: 'center'
  },
  {
    label: '日期',
    prop: 'date',
    format: 'YYYY-MM-DD HH:mm:ss',
    onclick: (row, event) => {
      console.log("xxxxxxxxxxxxxxx")
      console.log(row, event)
    }
  },
  {
    type: 'tag',
    label: '类型',
    prop: 'type',
    list: [
      { value: 1, label: '普通' },
      { value: 2, label: '会员' },
      { value: false, label: '禁用' },
      { value: true, label: '启用' },
    ],
    tagType: {
      1: 'warning',
      2: 'info',
      'xxx': 'primary',
      false: 'warning',
      true: 'primary',
      defalut: 'primary'
    },
    onclick: (row, event) => {
      console.log("xxxxxxxxxxxxxxx")
      console.log(row, event)
    }
  },
  {
      prop: 'name',
      renderHeader: (data) => {
        return h('span', null, '渲染 名字')
      },
      render: (row, column, cellValue, index) => {
        return h('span', null, '渲染 ' + row.name)
      },
    },

  {
    label: '个人信息',
    children: [
      {
        label: "名字",
        prop: 'name',
        renderHeader: (data) => {
          return h('span', null, '渲染 名字')
        },
        render: (row, column, cellValue, index) => {
          return h('span', null, '渲染 ' + row.name)
        },
      },
      {
        label: '手机号',
        prop: 'phone',
        slotHeader: 'slotHeader_phone',
        slot: 'slot_phone'
      },
      {
        label: "地址",
        prop: 'address',
        showOverflowTooltip:false
      },
      {
        type: 'image',
        label: "图片",
        prop: 'img',

    },
    ]
  },
  {
      label: "地址",
      prop: 'address',
      showOverflowTooltip:false
    },
]


// 获取数据方法
const getData = (param) : PageResponse | Promise<PageResponse> => {
  console.log('param',param)
  let { pageNum } = param
  pageNum = pageNum * 100
  const data = {
    total: 200,
    root: [
        {
        id: 1,
        date: '2016-05-02',
        name: 'wangxiaohu',
        phone: '1361111_' + pageNum,
        address: 'No. 189, Grove St, Los Angeles',
        type: 1,
        img: 'https://fuss10.elemecdn.com/d/e6/c4d93a3805b3ce3f323f7974e6f78jpeg.jpeg'
      },
      {
        id: 2,
        date: '2016-05-04',
        name: 'wangxiaohu',
        phone: '1361111_' + pageNum,
        address: 'No. 189, Grove St, Los Angeles',
        type: 2,
        img: 'https://fuss10.elemecdn.com/d/e6/c4d93a3805b3ce3f323f7974e6f78jpeg.jpeg'
      },
      {
        id: 3,
        date: '2016-05-01',
        name: 'wangxiaohu',
        phone: '1361111_' + pageNum,
        address: 'No. 189, Grove St, Los Angeles',
        type: 'xxx',
        img: 'https://fuss10.elemecdn.com/d/e6/c4d93a3805b3ce3f323f7974e6f78jpeg.jpeg',
        children: [
          {
            id: 31,
            date: '2016-05-01',
            name: 'wangxiaohu',
            phone: '1361111_' + pageNum,
            address: 'No. 189, Grove St, Los Angeles',
            type: false,
            img: 'https://fuss10.elemecdn.com/d/e6/c4d93a3805b3ce3f323f7974e6f78jpeg.jpeg',
          },
          {
            id: 32,
            date: '2016-05-01',
            name: 'wangxiaohu',
            phone: '1361111_' + pageNum,
            address: 'No. 189, Grove St, Los Angeles',
            type: true,
            img: 'https://fuss10.elemecdn.com/d/e6/c4d93a3805b3ce3f323f7974e6f78jpeg.jpeg',
          },
        ],
      },
      {
        id: 4,
        date: '2016-05-03',
        name: 'wangxiaohu',
        address: 'No. 189, Grove St, Los Angeles',
        type: 666,
        img: 'https://fuss10.elemecdn.com/d/e6/c4d93a3805b3ce3f323f7974e6f78jpeg.jpeg',
      },
    ]
  }


  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(data)
    }, 1000)
  })
}


</script>

<style scoped>

</style>
